#include "events.h"
#include <vector>

class EventListener
{
public:
    typedef std::pair<Events*,Events::OnEvent> Connection;
public:
    void regist(Events* evts,Events::OnEvent evt)
    {
        (*evts) += evt;
        events.push_back(std::make_pair(evts,evt));
    }

    virtual ~EventListener()
    {
        for(auto e : events)
        {
            (*e.first) -= e.second;
        }
    }
private:
    std::vector<Connection> events;
};


#define BIND_MEMBER_FUNCTION(fun) std::bind(&fun, this, std::placeholders::_1)
#define REGIST_MEMBER_FUNCTION(events,fun) regist(&events,BIND_MEMBER_FUNCTION(fun)))